package com.googlecode.horncomb.web.spring.context;

import org.springframework.context.ApplicationContext;

public class SpringContextLocator
{
    private static ApplicationContext rootApplicationContext = null;
    private static ThreadLocal<ApplicationContext> currentApplicationContext = new ThreadLocal<ApplicationContext>();

    public static ApplicationContext getCurrentApplicationContext()
    {
        ApplicationContext ctx = currentApplicationContext.get();
        return ctx == null ? rootApplicationContext : ctx;
    }

    public static void setCurrentApplicationContext(ApplicationContext ctx)
    {
        currentApplicationContext.set(ctx);
    }

    public static ApplicationContext getRootApplicationContext()
    {
        return rootApplicationContext;
    }

    public static void setRootApplicationContext(
            ApplicationContext applicationContext)
    {
        rootApplicationContext = applicationContext;
    }
}
